﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.ScriptableRenderContext
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.Bindings;
using UnityEngine.Rendering.RendererUtils;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>Defines state and drawing commands that custom render pipelines use.</para>
  /// </summary>
  [NativeType("Runtime/Graphics/ScriptableRenderLoop/ScriptableRenderContext.h")]
  [NativeHeader("Runtime/Graphics/ScriptableRenderLoop/ScriptableDrawRenderersUtility.h")]
  [NativeHeader("Runtime/Export/RenderPipeline/ScriptableRenderContext.bindings.h")]
  [NativeHeader("Runtime/Export/RenderPipeline/ScriptableRenderPipeline.bindings.h")]
  [NativeHeader("Modules/UI/Canvas.h")]
  [NativeHeader("Modules/UI/CanvasManager.h")]
  public struct ScriptableRenderContext : IEquatable<ScriptableRenderContext>
  {
    private static readonly ShaderTagId kRenderTypeTag = new ShaderTagId("RenderType");
    private IntPtr m_Ptr;
    private AtomicSafetyHandle m_Safety;

    [FreeFunction("ScriptableRenderContext::BeginRenderPass")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void BeginRenderPass_Internal(
      IntPtr self,
      int width,
      int height,
      int samples,
      IntPtr colors,
      int colorCount,
      int depthAttachmentIndex);

    [FreeFunction("ScriptableRenderContext::BeginSubPass")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void BeginSubPass_Internal(
      IntPtr self,
      IntPtr colors,
      int colorCount,
      IntPtr inputs,
      int inputCount,
      bool isDepthReadOnly,
      bool isStencilReadOnly);

    [FreeFunction("ScriptableRenderContext::EndSubPass")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void EndSubPass_Internal(IntPtr self);

    [FreeFunction("ScriptableRenderContext::EndRenderPass")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void EndRenderPass_Internal(IntPtr self);

    [FreeFunction("ScriptableRenderPipeline_Bindings::Internal_Cull")]
    private static void Internal_Cull(
      ref ScriptableCullingParameters parameters,
      ScriptableRenderContext renderLoop,
      IntPtr results)
    {
      ScriptableRenderContext.Internal_Cull_Injected(ref parameters, ref renderLoop, results);
    }

    [FreeFunction("InitializeSortSettings")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern void InitializeSortSettings(
      Camera camera,
      out SortingSettings sortingSettings);

    private void Submit_Internal() => ScriptableRenderContext.Submit_Internal_Injected(ref this);

    private bool SubmitForRenderPassValidation_Internal()
    {
      return ScriptableRenderContext.SubmitForRenderPassValidation_Internal_Injected(ref this);
    }

    private void GetCameras_Internal(System.Type listType, object resultList)
    {
      ScriptableRenderContext.GetCameras_Internal_Injected(ref this, listType, resultList);
    }

    private void DrawRenderers_Internal(
      IntPtr cullResults,
      ref DrawingSettings drawingSettings,
      ref FilteringSettings filteringSettings,
      ShaderTagId tagName,
      bool isPassTagName,
      IntPtr tagValues,
      IntPtr stateBlocks,
      int stateCount)
    {
      ScriptableRenderContext.DrawRenderers_Internal_Injected(ref this, cullResults, ref drawingSettings, ref filteringSettings, ref tagName, isPassTagName, tagValues, stateBlocks, stateCount);
    }

    private void DrawShadows_Internal(IntPtr shadowDrawingSettings)
    {
      ScriptableRenderContext.DrawShadows_Internal_Injected(ref this, shadowDrawingSettings);
    }

    /// <summary>
    ///   <para>Emits UI geometry into the Scene view for rendering.</para>
    /// </summary>
    /// <param name="cullingCamera">Camera to emit the geometry for.</param>
    [FreeFunction("UI::GetCanvasManager().EmitWorldGeometryForSceneView")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void EmitWorldGeometryForSceneView(Camera cullingCamera);

    /// <summary>
    ///   <para>Emits UI geometry for rendering for the specified camera.</para>
    /// </summary>
    /// <param name="camera">Camera to emit the geometry for.</param>
    [FreeFunction("UI::GetCanvasManager().EmitGeometryForCamera")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern void EmitGeometryForCamera(Camera camera);

    [NativeThrows]
    private void ExecuteCommandBuffer_Internal(CommandBuffer commandBuffer)
    {
      ScriptableRenderContext.ExecuteCommandBuffer_Internal_Injected(ref this, commandBuffer);
    }

    [NativeThrows]
    private void ExecuteCommandBufferAsync_Internal(
      CommandBuffer commandBuffer,
      ComputeQueueType queueType)
    {
      ScriptableRenderContext.ExecuteCommandBufferAsync_Internal_Injected(ref this, commandBuffer, queueType);
    }

    private void SetupCameraProperties_Internal([NotNull("NullExceptionObject")] Camera camera, bool stereoSetup, int eye)
    {
      ScriptableRenderContext.SetupCameraProperties_Internal_Injected(ref this, camera, stereoSetup, eye);
    }

    private void StereoEndRender_Internal([NotNull("NullExceptionObject")] Camera camera, int eye, bool isFinalPass)
    {
      ScriptableRenderContext.StereoEndRender_Internal_Injected(ref this, camera, eye, isFinalPass);
    }

    private void StartMultiEye_Internal([NotNull("NullExceptionObject")] Camera camera, int eye)
    {
      ScriptableRenderContext.StartMultiEye_Internal_Injected(ref this, camera, eye);
    }

    private void StopMultiEye_Internal([NotNull("NullExceptionObject")] Camera camera)
    {
      ScriptableRenderContext.StopMultiEye_Internal_Injected(ref this, camera);
    }

    private void DrawSkybox_Internal([NotNull("NullExceptionObject")] Camera camera)
    {
      ScriptableRenderContext.DrawSkybox_Internal_Injected(ref this, camera);
    }

    private void InvokeOnRenderObjectCallback_Internal()
    {
      ScriptableRenderContext.InvokeOnRenderObjectCallback_Internal_Injected(ref this);
    }

    private void DrawGizmos_Internal([NotNull("NullExceptionObject")] Camera camera, GizmoSubset gizmoSubset)
    {
      ScriptableRenderContext.DrawGizmos_Internal_Injected(ref this, camera, gizmoSubset);
    }

    private void DrawWireOverlay_Impl([NotNull("NullExceptionObject")] Camera camera)
    {
      ScriptableRenderContext.DrawWireOverlay_Impl_Injected(ref this, camera);
    }

    private void DrawUIOverlay_Internal([NotNull("NullExceptionObject")] Camera camera)
    {
      ScriptableRenderContext.DrawUIOverlay_Internal_Injected(ref this, camera);
    }

    internal IntPtr Internal_GetPtr() => this.m_Ptr;

    private RendererList CreateRendererList_Internal(
      IntPtr cullResults,
      ref DrawingSettings drawingSettings,
      ref FilteringSettings filteringSettings,
      ShaderTagId tagName,
      bool isPassTagName,
      IntPtr tagValues,
      IntPtr stateBlocks,
      int stateCount)
    {
      RendererList ret;
      ScriptableRenderContext.CreateRendererList_Internal_Injected(ref this, cullResults, ref drawingSettings, ref filteringSettings, ref tagName, isPassTagName, tagValues, stateBlocks, stateCount, out ret);
      return ret;
    }

    private void PrepareRendererListsAsync_Internal(object rendererLists)
    {
      ScriptableRenderContext.PrepareRendererListsAsync_Internal_Injected(ref this, rendererLists);
    }

    private RendererListStatus QueryRendererListStatus_Internal(RendererList handle)
    {
      return ScriptableRenderContext.QueryRendererListStatus_Internal_Injected(ref this, ref handle);
    }

    internal ScriptableRenderContext(IntPtr ptr, AtomicSafetyHandle safety)
    {
      this.m_Ptr = ptr;
      this.m_Safety = safety;
    }

    public unsafe void BeginRenderPass(
      int width,
      int height,
      int samples,
      NativeArray<AttachmentDescriptor> attachments,
      int depthAttachmentIndex = -1)
    {
      this.Validate();
      ScriptableRenderContext.BeginRenderPass_Internal(this.m_Ptr, width, height, samples, (IntPtr) attachments.GetUnsafeReadOnlyPtr<AttachmentDescriptor>(), attachments.Length, depthAttachmentIndex);
    }

    public ScopedRenderPass BeginScopedRenderPass(
      int width,
      int height,
      int samples,
      NativeArray<AttachmentDescriptor> attachments,
      int depthAttachmentIndex = -1)
    {
      this.BeginRenderPass(width, height, samples, attachments, depthAttachmentIndex);
      return new ScopedRenderPass(this);
    }

    public unsafe void BeginSubPass(
      NativeArray<int> colors,
      NativeArray<int> inputs,
      bool isDepthReadOnly,
      bool isStencilReadOnly)
    {
      this.Validate();
      ScriptableRenderContext.BeginSubPass_Internal(this.m_Ptr, (IntPtr) colors.GetUnsafeReadOnlyPtr<int>(), colors.Length, (IntPtr) inputs.GetUnsafeReadOnlyPtr<int>(), inputs.Length, isDepthReadOnly, isStencilReadOnly);
    }

    public unsafe void BeginSubPass(
      NativeArray<int> colors,
      NativeArray<int> inputs,
      bool isDepthStencilReadOnly = false)
    {
      this.Validate();
      ScriptableRenderContext.BeginSubPass_Internal(this.m_Ptr, (IntPtr) colors.GetUnsafeReadOnlyPtr<int>(), colors.Length, (IntPtr) inputs.GetUnsafeReadOnlyPtr<int>(), inputs.Length, isDepthStencilReadOnly, isDepthStencilReadOnly);
    }

    public unsafe void BeginSubPass(
      NativeArray<int> colors,
      bool isDepthReadOnly,
      bool isStencilReadOnly)
    {
      this.Validate();
      ScriptableRenderContext.BeginSubPass_Internal(this.m_Ptr, (IntPtr) colors.GetUnsafeReadOnlyPtr<int>(), colors.Length, IntPtr.Zero, 0, isDepthReadOnly, isStencilReadOnly);
    }

    public unsafe void BeginSubPass(NativeArray<int> colors, bool isDepthStencilReadOnly = false)
    {
      this.Validate();
      ScriptableRenderContext.BeginSubPass_Internal(this.m_Ptr, (IntPtr) colors.GetUnsafeReadOnlyPtr<int>(), colors.Length, IntPtr.Zero, 0, isDepthStencilReadOnly, isDepthStencilReadOnly);
    }

    public ScopedSubPass BeginScopedSubPass(
      NativeArray<int> colors,
      NativeArray<int> inputs,
      bool isDepthReadOnly,
      bool isStencilReadOnly)
    {
      this.BeginSubPass(colors, inputs, isDepthReadOnly, isStencilReadOnly);
      return new ScopedSubPass(this);
    }

    public ScopedSubPass BeginScopedSubPass(
      NativeArray<int> colors,
      NativeArray<int> inputs,
      bool isDepthStencilReadOnly = false)
    {
      this.BeginSubPass(colors, inputs, isDepthStencilReadOnly);
      return new ScopedSubPass(this);
    }

    public ScopedSubPass BeginScopedSubPass(
      NativeArray<int> colors,
      bool isDepthReadOnly,
      bool isStencilReadOnly)
    {
      this.BeginSubPass(colors, isDepthReadOnly, isStencilReadOnly);
      return new ScopedSubPass(this);
    }

    public ScopedSubPass BeginScopedSubPass(NativeArray<int> colors, bool isDepthStencilReadOnly = false)
    {
      this.BeginSubPass(colors, isDepthStencilReadOnly);
      return new ScopedSubPass(this);
    }

    /// <summary>
    ///   <para>Schedules the end of the currently active sub pass.</para>
    /// </summary>
    public void EndSubPass()
    {
      this.Validate();
      ScriptableRenderContext.EndSubPass_Internal(this.m_Ptr);
    }

    /// <summary>
    ///   <para>Schedules the end of a currently active render pass.</para>
    /// </summary>
    public void EndRenderPass()
    {
      this.Validate();
      ScriptableRenderContext.EndRenderPass_Internal(this.m_Ptr);
    }

    /// <summary>
    ///   <para>Submits all the scheduled commands to the rendering loop for execution.</para>
    /// </summary>
    public void Submit()
    {
      this.Validate();
      this.Submit_Internal();
    }

    /// <summary>
    ///   <para>This method submits all the scheduled commands to the rendering loop for validation. The validation checks whether render passes that were started with the BeginRenderPass call can execute the scheduled commands.</para>
    /// </summary>
    public bool SubmitForRenderPassValidation()
    {
      this.Validate();
      return this.SubmitForRenderPassValidation_Internal();
    }

    internal void GetCameras(List<Camera> results)
    {
      this.Validate();
      this.GetCameras_Internal(typeof (Camera), (object) results);
    }

    public void DrawRenderers(
      CullingResults cullingResults,
      ref DrawingSettings drawingSettings,
      ref FilteringSettings filteringSettings)
    {
      this.Validate();
      cullingResults.Validate();
      this.DrawRenderers_Internal(cullingResults.ptr, ref drawingSettings, ref filteringSettings, ShaderTagId.none, false, IntPtr.Zero, IntPtr.Zero, 0);
    }

    public unsafe void DrawRenderers(
      CullingResults cullingResults,
      ref DrawingSettings drawingSettings,
      ref FilteringSettings filteringSettings,
      ref RenderStateBlock stateBlock)
    {
      this.Validate();
      cullingResults.Validate();
      ShaderTagId shaderTagId = new ShaderTagId();
      fixed (RenderStateBlock* stateBlocks = &stateBlock)
        this.DrawRenderers_Internal(cullingResults.ptr, ref drawingSettings, ref filteringSettings, ShaderTagId.none, false, (IntPtr) (void*) &shaderTagId, (IntPtr) (void*) stateBlocks, 1);
    }

    public unsafe void DrawRenderers(
      CullingResults cullingResults,
      ref DrawingSettings drawingSettings,
      ref FilteringSettings filteringSettings,
      NativeArray<ShaderTagId> renderTypes,
      NativeArray<RenderStateBlock> stateBlocks)
    {
      this.Validate();
      cullingResults.Validate();
      if (renderTypes.Length != stateBlocks.Length)
        throw new ArgumentException(string.Format("Arrays {0} and {1} should have same length, but {2} had length {3} while {4} had length {5}.", (object) nameof (renderTypes), (object) nameof (stateBlocks), (object) nameof (renderTypes), (object) renderTypes.Length, (object) nameof (stateBlocks), (object) stateBlocks.Length));
      this.DrawRenderers_Internal(cullingResults.ptr, ref drawingSettings, ref filteringSettings, ScriptableRenderContext.kRenderTypeTag, false, (IntPtr) renderTypes.GetUnsafeReadOnlyPtr<ShaderTagId>(), (IntPtr) stateBlocks.GetUnsafeReadOnlyPtr<RenderStateBlock>(), renderTypes.Length);
    }

    public unsafe void DrawRenderers(
      CullingResults cullingResults,
      ref DrawingSettings drawingSettings,
      ref FilteringSettings filteringSettings,
      ShaderTagId tagName,
      bool isPassTagName,
      NativeArray<ShaderTagId> tagValues,
      NativeArray<RenderStateBlock> stateBlocks)
    {
      this.Validate();
      cullingResults.Validate();
      if (tagValues.Length != stateBlocks.Length)
        throw new ArgumentException(string.Format("Arrays {0} and {1} should have same length, but {2} had length {3} while {4} had length {5}.", (object) nameof (tagValues), (object) nameof (stateBlocks), (object) nameof (tagValues), (object) tagValues.Length, (object) nameof (stateBlocks), (object) stateBlocks.Length));
      this.DrawRenderers_Internal(cullingResults.ptr, ref drawingSettings, ref filteringSettings, tagName, isPassTagName, (IntPtr) tagValues.GetUnsafeReadOnlyPtr<ShaderTagId>(), (IntPtr) stateBlocks.GetUnsafeReadOnlyPtr<RenderStateBlock>(), tagValues.Length);
    }

    public unsafe void DrawShadows(ref ShadowDrawingSettings settings)
    {
      this.Validate();
      settings.cullingResults.Validate();
      fixed (ShadowDrawingSettings* shadowDrawingSettings = &settings)
        this.DrawShadows_Internal((IntPtr) (void*) shadowDrawingSettings);
    }

    /// <summary>
    ///   <para>Schedules the execution of a custom graphics Command Buffer.</para>
    /// </summary>
    /// <param name="commandBuffer">Specifies the Command Buffer to execute.</param>
    public void ExecuteCommandBuffer(CommandBuffer commandBuffer)
    {
      if (commandBuffer == null)
        throw new ArgumentNullException(nameof (commandBuffer));
      if (commandBuffer.m_Ptr == IntPtr.Zero)
        throw new ObjectDisposedException(nameof (commandBuffer));
      this.Validate();
      this.ExecuteCommandBuffer_Internal(commandBuffer);
    }

    /// <summary>
    ///   <para>Schedules the execution of a Command Buffer on an async compute queue. The ComputeQueueType that you pass in determines the queue order.</para>
    /// </summary>
    /// <param name="commandBuffer">The CommandBuffer to be executed.</param>
    /// <param name="queueType">Describes the desired async compute queue the supplied CommandBuffer should be executed on.</param>
    public void ExecuteCommandBufferAsync(CommandBuffer commandBuffer, ComputeQueueType queueType)
    {
      if (commandBuffer == null)
        throw new ArgumentNullException(nameof (commandBuffer));
      if (commandBuffer.m_Ptr == IntPtr.Zero)
        throw new ObjectDisposedException(nameof (commandBuffer));
      this.Validate();
      this.ExecuteCommandBufferAsync_Internal(commandBuffer, queueType);
    }

    /// <summary>
    ///   <para>Schedules the setup of Camera specific global Shader variables.</para>
    /// </summary>
    /// <param name="camera">Camera to setup shader variables for.</param>
    /// <param name="stereoSetup">Set up the stereo shader variables and state.</param>
    /// <param name="eye">The current eye to be rendered.</param>
    public void SetupCameraProperties(Camera camera, bool stereoSetup = false)
    {
      this.SetupCameraProperties(camera, stereoSetup, 0);
    }

    /// <summary>
    ///   <para>Schedules the setup of Camera specific global Shader variables.</para>
    /// </summary>
    /// <param name="camera">Camera to setup shader variables for.</param>
    /// <param name="stereoSetup">Set up the stereo shader variables and state.</param>
    /// <param name="eye">The current eye to be rendered.</param>
    public void SetupCameraProperties(Camera camera, bool stereoSetup, int eye)
    {
      this.Validate();
      this.SetupCameraProperties_Internal(camera, stereoSetup, eye);
    }

    /// <summary>
    ///   <para>Schedule notification of completion of stereo rendering on a single frame.</para>
    /// </summary>
    /// <param name="camera">Camera to indicate completion of stereo rendering.</param>
    /// <param name="eye">The current eye to be rendered.</param>
    /// <param name="isFinalPass"></param>
    public void StereoEndRender(Camera camera) => this.StereoEndRender(camera, 0, true);

    /// <summary>
    ///   <para>Schedule notification of completion of stereo rendering on a single frame.</para>
    /// </summary>
    /// <param name="camera">Camera to indicate completion of stereo rendering.</param>
    /// <param name="eye">The current eye to be rendered.</param>
    /// <param name="isFinalPass"></param>
    public void StereoEndRender(Camera camera, int eye) => this.StereoEndRender(camera, eye, true);

    /// <summary>
    ///   <para>Schedule notification of completion of stereo rendering on a single frame.</para>
    /// </summary>
    /// <param name="camera">Camera to indicate completion of stereo rendering.</param>
    /// <param name="eye">The current eye to be rendered.</param>
    /// <param name="isFinalPass"></param>
    public void StereoEndRender(Camera camera, int eye, bool isFinalPass)
    {
      this.Validate();
      this.StereoEndRender_Internal(camera, eye, isFinalPass);
    }

    /// <summary>
    ///   <para>Schedules a fine-grained beginning of stereo rendering on the ScriptableRenderContext.</para>
    /// </summary>
    /// <param name="camera">Camera to enable stereo rendering on.</param>
    /// <param name="eye">The current eye to be rendered.</param>
    public void StartMultiEye(Camera camera) => this.StartMultiEye(camera, 0);

    /// <summary>
    ///   <para>Schedules a fine-grained beginning of stereo rendering on the ScriptableRenderContext.</para>
    /// </summary>
    /// <param name="camera">Camera to enable stereo rendering on.</param>
    /// <param name="eye">The current eye to be rendered.</param>
    public void StartMultiEye(Camera camera, int eye)
    {
      this.Validate();
      this.StartMultiEye_Internal(camera, eye);
    }

    /// <summary>
    ///   <para>Schedules a stop of stereo rendering on the ScriptableRenderContext.</para>
    /// </summary>
    /// <param name="camera">Camera to disable stereo rendering on.</param>
    public void StopMultiEye(Camera camera)
    {
      this.Validate();
      this.StopMultiEye_Internal(camera);
    }

    /// <summary>
    ///   <para>Schedules the drawing of the skybox.</para>
    /// </summary>
    /// <param name="camera">Camera to draw the skybox for.</param>
    public void DrawSkybox(Camera camera)
    {
      this.Validate();
      this.DrawSkybox_Internal(camera);
    }

    /// <summary>
    ///   <para>Schedules an invocation of the OnRenderObject callback for MonoBehaviour scripts.</para>
    /// </summary>
    public void InvokeOnRenderObjectCallback()
    {
      this.Validate();
      this.InvokeOnRenderObjectCallback_Internal();
    }

    /// <summary>
    ///   <para>Schedules the drawing of a subset of Gizmos (before or after post-processing) for the given Camera.</para>
    /// </summary>
    /// <param name="camera">The camera of the current view.</param>
    /// <param name="gizmoSubset">Set to GizmoSubset.PreImageEffects to draw Gizmos that should be affected by postprocessing, or GizmoSubset.PostImageEffects to draw Gizmos that should not be affected by postprocessing. See also: GizmoSubset.</param>
    public void DrawGizmos(Camera camera, GizmoSubset gizmoSubset)
    {
      this.Validate();
      this.DrawGizmos_Internal(camera, gizmoSubset);
    }

    /// <summary>
    ///   <para>Schedules the drawing of a wireframe overlay for a given Scene view Camera.</para>
    /// </summary>
    /// <param name="camera">The Scene view Camera to draw the overlay for.</param>
    public void DrawWireOverlay(Camera camera)
    {
      this.Validate();
      this.DrawWireOverlay_Impl(camera);
    }

    /// <summary>
    ///   <para>Draw the UI overlay.</para>
    /// </summary>
    /// <param name="camera">The camera of the current view.</param>
    public void DrawUIOverlay(Camera camera)
    {
      this.Validate();
      this.DrawUIOverlay_Internal(camera);
    }

    public unsafe CullingResults Cull(ref ScriptableCullingParameters parameters)
    {
      CullingResults cullingResults = new CullingResults();
      ScriptableRenderContext.Internal_Cull(ref parameters, this, (IntPtr) (void*) &cullingResults);
      return cullingResults;
    }

    [Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
    internal void Validate()
    {
      if (this.m_Ptr.ToInt64() == 0L)
        throw new InvalidOperationException("The ScriptableRenderContext instance is invalid. This can happen if you construct an instance using the default constructor.");
      try
      {
        AtomicSafetyHandle.CheckExistsAndThrow(in this.m_Safety);
      }
      catch (Exception ex)
      {
        throw new InvalidOperationException("The ScriptableRenderContext instance is no longer valid. This can happen if you re-use it across multiple frames.", ex);
      }
    }

    public bool Equals(ScriptableRenderContext other) => this.m_Ptr.Equals((object) other.m_Ptr);

    public override bool Equals(object obj)
    {
      return obj != null && obj is ScriptableRenderContext other && this.Equals(other);
    }

    public override int GetHashCode() => this.m_Ptr.GetHashCode();

    public static bool operator ==(ScriptableRenderContext left, ScriptableRenderContext right)
    {
      return left.Equals(right);
    }

    public static bool operator !=(ScriptableRenderContext left, ScriptableRenderContext right)
    {
      return !left.Equals(right);
    }

    /// <summary>
    ///   <para>Creates a new RendererList.</para>
    /// </summary>
    /// <param name="desc">A descriptor that represents the set of GameObjects the RendererList contains.</param>
    /// <returns>
    ///   <para>Returns a new RendererList based on the RendererListDesc you pass in.</para>
    /// </returns>
    public unsafe RendererList CreateRendererList(RendererListDesc desc)
    {
      this.Validate();
      RendererListParams rendererListParams = RendererListParams.Create(in desc);
      if (!rendererListParams.stateBlock.HasValue)
        return this.CreateRendererList_Internal(rendererListParams.cullingResult.ptr, ref rendererListParams.drawSettings, ref rendererListParams.filteringSettings, ShaderTagId.none, false, IntPtr.Zero, IntPtr.Zero, 0);
      ShaderTagId shaderTagId = new ShaderTagId();
      RenderStateBlock* stateBlocks = &rendererListParams.stateBlock.Value;
      return this.CreateRendererList_Internal(rendererListParams.cullingResult.ptr, ref rendererListParams.drawSettings, ref rendererListParams.filteringSettings, ShaderTagId.none, false, (IntPtr) (void*) &shaderTagId, (IntPtr) (void*) stateBlocks, 1);
    }

    public void PrepareRendererListsAsync(List<RendererList> rendererLists)
    {
      this.Validate();
      this.PrepareRendererListsAsync_Internal((object) rendererLists);
    }

    /// <summary>
    ///   <para>Queries the status of a RendererList.</para>
    /// </summary>
    /// <param name="rendererList">The RendererList to query.</param>
    /// <returns>
    ///   <para>Returns the status of the RendererList.</para>
    /// </returns>
    public RendererListStatus QueryRendererListStatus(RendererList rendererList)
    {
      this.Validate();
      return this.QueryRendererListStatus_Internal(rendererList);
    }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void Internal_Cull_Injected(
      ref ScriptableCullingParameters parameters,
      ref ScriptableRenderContext renderLoop,
      IntPtr results);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void Submit_Internal_Injected(ref ScriptableRenderContext _unity_self);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool SubmitForRenderPassValidation_Internal_Injected(
      ref ScriptableRenderContext _unity_self);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetCameras_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      System.Type listType,
      object resultList);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void DrawRenderers_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      IntPtr cullResults,
      ref DrawingSettings drawingSettings,
      ref FilteringSettings filteringSettings,
      ref ShaderTagId tagName,
      bool isPassTagName,
      IntPtr tagValues,
      IntPtr stateBlocks,
      int stateCount);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void DrawShadows_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      IntPtr shadowDrawingSettings);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void ExecuteCommandBuffer_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      CommandBuffer commandBuffer);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void ExecuteCommandBufferAsync_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      CommandBuffer commandBuffer,
      ComputeQueueType queueType);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetupCameraProperties_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      Camera camera,
      bool stereoSetup,
      int eye);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void StereoEndRender_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      Camera camera,
      int eye,
      bool isFinalPass);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void StartMultiEye_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      Camera camera,
      int eye);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void StopMultiEye_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      Camera camera);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void DrawSkybox_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      Camera camera);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void InvokeOnRenderObjectCallback_Internal_Injected(
      ref ScriptableRenderContext _unity_self);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void DrawGizmos_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      Camera camera,
      GizmoSubset gizmoSubset);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void DrawWireOverlay_Impl_Injected(
      ref ScriptableRenderContext _unity_self,
      Camera camera);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void DrawUIOverlay_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      Camera camera);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void CreateRendererList_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      IntPtr cullResults,
      ref DrawingSettings drawingSettings,
      ref FilteringSettings filteringSettings,
      ref ShaderTagId tagName,
      bool isPassTagName,
      IntPtr tagValues,
      IntPtr stateBlocks,
      int stateCount,
      out RendererList ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void PrepareRendererListsAsync_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      object rendererLists);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern RendererListStatus QueryRendererListStatus_Internal_Injected(
      ref ScriptableRenderContext _unity_self,
      ref RendererList handle);
  }
}
